﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using easyList.IO.Writer;

namespace easyList.Options
{
    class OptionManager
    {
        //this class contains variables and methods to read and save the program options


        static OptionManager instance = null;
        static readonly object padlock = new object();

        Boolean allowedFormatsEnabled = true;
        List<String> allowedFormats = new List<String>();

        Boolean ignoredFormatsEnabled = false;
        List<String> ignoredFormats = new List<String>();

        OptionManager()
        {
            allowedFormats.Add("*");
            //ignoredFormats.Add();
        }




        public static OptionManager Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new OptionManager();
                    }
                    return instance;
                }
            }
        }


        public void setOptions(bool allowedFormatsEnabled, bool ignoredFormatsEnabled, string allowedFormats, string ignoredFormats)
        {
            this.allowedFormatsEnabled = allowedFormatsEnabled;
            this.ignoredFormatsEnabled = ignoredFormatsEnabled;

            

        }

        //set the allowed options, this is usually called after "OK" is clicked in options menu
        public void setAllowedFormats(string allowedformatoptionstring){

            //divide string to its parts, separator ;

            //add to list


            List<String> allowedFormatsList = new List<String>(); 
            //save list
            allowedFormats = allowedFormatsList;
        }



        internal void setIgnoredFormats(string p)
        {
           // throw new NotImplementedException();
        }


        private List<String> createListFromFormatListInput(string formatstringinput)
        {
            return null;
        }

        private void loadOptionsFromDisk()
        {

        }

        public void writeOptionsToDisk()
        {
            string configcontent = "[easyListConfiguration]\n";

            configcontent = configcontent + "allowedFormatsEnabled=" + allowedFormatsEnabled.ToString() + "\n";
            configcontent = configcontent + "ignoredFormatsEnabled=" + ignoredFormatsEnabled.ToString() + "\n";

            configcontent = configcontent + "allowedFormats=" + convertListToFormatString(allowedFormats) + "\n";
            configcontent = configcontent + "ignoredFormats=" + convertListToFormatString(ignoredFormats) + "\n";

            //write to file
            TXTWriter writer = TXTWriter.Instance;
            writer.writeTXT(configcontent);
        }

        private string convertListToFormatString(List<String> list)
        {
            string r = "";
            foreach( String current in list)
            {
                r = r + current;
            }
            return r;
        }

    }
}
